<%@ include file="css/header.jsp" %>
<title>Login</title>
<script type="text/javascript">
$(document).ready(function() {
	
	
    	$("#btnLogin").click(function(){
    		login();
            return false;
        });

 
});
function login(){
	 var formObj = $("#formLogin");
    var data = formObj.serialize();
        $.ajax({
            type: 'POST',
            url: '<%=request.getContextPath()%>/LoginServlet',
            data: data,
            dataType: 'json',
            success: function(data){
                $.each(data, function(key, value) {
                    //Validate is error send?
                    if (key == 'not') {
                       $("#error").show();
                    } else if(key == 'success'){ //No Error
                       window.location.href = "ViewServlet";
                    } else if(key == 'error'){
                    	$.msgbox(value, {
                            type : 'error'
                        }, function(buttonPressed) {
                        
                        });
                    }
                    return false; //break each loop
                });
            },
            error: function(jqXHR, textStatus, errorThrown){
                $.msgbox('Server error.', {
                    type : 'error'
                }, function(buttonPressed) {
                    // your code here
                });
            }
        }); }

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   login();
   return false;
   }
else
   return true;
}
 </script>
</head>
<body>
	<div id="jp-main">
        <div class="jp-sheet">
            <div class="jp-sheet-tl"></div>
            <div class="jp-sheet-tr"></div>
            <div class="jp-sheet-bl"></div>
            <div class="jp-sheet-br"></div>
            <div class="jp-sheet-tc"></div>
            <div class="jp-sheet-bc"></div>
            <div class="jp-sheet-cl"></div>
            <div class="jp-sheet-cr"></div>
            <div class="jp-sheet-cc"></div>
            <div class="jp-sheet-body">
                <div class="jp-header">
                    <div class="jp-header-center">
                        <div class="jp-header-png"></div>
                        <div class="jp-header-jpeg"></div>
                    </div>
                        <div class="jp-header-fluid-object"></div>
                </div>
                <div class="jp-nav">
                	<div class="l"></div>
                	<div class="r"></div>
                	<ul class="jp-menu">
                		<li>
                			<a href="#" class="active"><span class="l"></span><span class="r"></span><span class="t">LOGIN</span></a>                		</li>
           		 
			 
           			</ul>
               		  </li>		
           		
               	  </ul>
                </div>
                <div class="jp-content-layout">
                    
                       
                  <div class="jp-post-body">
  <div class="login_form">

    <h5 align="center">LOGIN</h5>

   <p id="error" class="error" style="display: none;">Incorrect Username or Password!</p>

    <form id ="formLogin" action="#" method="post">

        <label>Username</label>

        <input type="text" class="inputText" name="username" id="username" onKeyPress="return submitenter(this,event)"v/>

        <label>Password</label>

        <input type="password" class="inputText" name="password" id="password" onKeyPress="return submitenter(this,event)" />

        <br clear="all" />

        <button type="button" class="green" id="btnLogin" style="cursor: pointer;">Log in</button>

    </form>
   </div>
                  </div>
                </div>
            </div>
        </div>
</div>
    
    
    
    
    
</body>

</html>